package com.ohs.ohsoa.system.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ohs.ohsoa.system.dto.LeaveSettingDto;
import com.ohs.ohsoa.system.entity.LeaveSetting;
import com.ohs.ohsoa.system.mapper.LeavesettingMapper;
import com.ohs.ohsoa.utils.IsNull;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门实现类
 *
 * @author ss
 *
 */
@Service
public class LeavesettingServiceImpl extends ServiceImpl<LeavesettingMapper, LeaveSetting> implements LeavesettingService {

    @Resource
    private LeavesettingMapper leavesettingMapper;

    @Resource
    private LeavesettingService leavesettingService;

    @Override
    public List<LeaveSetting> overtimesettingSelectList(PageParam<LeaveSetting> pageParam) {
        // 获取LeaveSetting对象
        LeaveSetting leaveSetting = pageParam.getSearchbean();
        // 分页
        PageHelper.startPage(pageParam.getIndexPage(), pageParam.getPageSize());
        QueryWrapper<LeaveSetting> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(IsNull.isNotNull(leaveSetting.getGroupEnterpriseGuid()),"group_enterprise_guid",leaveSetting.getGroupEnterpriseGuid())
        .like(IsNull.isNotNull(leaveSetting.getLsName()),"ls_name",leaveSetting.getLsName());
        return this.list(queryWrapper);
    }

    @Override
    public Boolean leaveSettingInsert(LeaveSetting leaveSetting) {
        String yearMonthDay = "1900-01-01 ";
        leaveSetting.setLsBtime(yearMonthDay + leaveSetting.getLsBtime());
        leaveSetting.setLsEtime(yearMonthDay + leaveSetting.getLsEtime());
        return leavesettingMapper.LeavesettingInsert(leaveSetting);
    }

    @Override
    public Boolean leaveSettingUpdate(LeaveSetting leaveSetting) {
        String yearMonthDay = "1900-01-01 ";
        leaveSetting.setLsBtime(yearMonthDay + leaveSetting.getLsBtime());
        leaveSetting.setLsEtime(yearMonthDay + leaveSetting.getLsEtime());
        return leavesettingService.saveOrUpdate(leaveSetting);
    }

    @Override
    public Boolean leaveSettingDelete(LeaveSettingDto leaveSettingDto) {
        return leavesettingMapper.LeavesettingDelete(leaveSettingDto.getLsGuids());
    }


}
